﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Zentrum.Calendar
{
	/// <summary>
	/// A clock that always returns a time based on a baseline time.
	/// </summary>
	public class BaselineClock : IClock
	{
		private readonly DateTime m_Local;
		private readonly DateTime m_Utc;

		private readonly DateTime m_CaptureTime;

		/// <summary>
		/// Initializes the instance
		/// </summary>
		/// <param name="baseline">The date and time that will be the basis of time</param>
		public BaselineClock(DateTime baseline)
		{
			m_Local=baseline.ToLocalTime();
			m_Utc=baseline.ToUniversalTime();

			m_CaptureTime=DateTime.UtcNow;
		}

		/// <summary>
		/// Returns the local time
		/// </summary>
		public DateTime Now
		{
			get
			{
				TimeSpan delta=DateTime.UtcNow-m_CaptureTime;
				return m_Local+delta;
			}
		}

		/// <summary>
		/// Returns the utc time
		/// </summary>
		public DateTime UtcNow
		{
			get
			{
				TimeSpan delta=DateTime.UtcNow-m_CaptureTime;
				return m_Utc+delta;
			}
		}
	}
}
